{#
/**
 * @file
 * container
 *
 * See container.wingsuit.yaml for documentation.
 */
#}

{# Defaults #}
{% set width = width|default('default') %}

{#
  Padding x defaults:
  The container x padding is allways "default" for all widhts.
  Only width "full" removes the padding_x completly.
#}
{% set padding_x = width != 'full' ? padding_x|default('default') : '' %}

{#
  Padding top/bottom defaults:
  Very basic logic for vertical spacing. Each "auto" container has a default spacing to bottom.
  If a background color is adjusted a "default" padding to top is adjusted.
  The user can allways overwrite the this behavior.
#}
{% set padding_top = padding_top|default('auto') == 'auto' and (bg is not empty or bg_image is not empty )  ? 'default' : padding_top %}
{% set padding_bottom = padding_bottom|default('auto') == 'auto' ? 'default' : padding_bottom %}

{# Settings #}
{% set bg_classes = ([
  pattern_configuration('container', '', 'bg')[bg],
  'absolute left-0 top-0 w-full h-full overflow-hidden background-cover'
] | sort | join(' ') | trim )%}

{% set classes = ([
  is_layout_builder == false ? pattern_configuration('spacing', '', 'margin_top')[margin_top],
  pattern_configuration('spacing', '', 'padding_x')[padding_x],
  pattern_configuration('spacing', '', 'padding_top')[padding_top],
  pattern_configuration('spacing', '', 'padding_bottom')[padding_bottom],
  pattern_configuration('container', '', 'width')[width],
  classes,
  'mx-auto w-full'
] | sort | join(' ') | trim )%}

{% set attributes = attributes|default(create_attribute()) %}

{# TEMPLATE #}
{% if bg or bg_image or is_relative%}
<div class="relative">
  {% if bg_image or bg %}<div {{ create_attribute().addClass(bg_classes) }} style="z-index: -1">{{ bg_image }}</div>{% endif %}
{% endif %}
  <div {{ attributes.addClass(classes) }}>
    {% block content %}
      {{ content }}
    {% endblock %}
  </div>
{% if bg or bg_image or is_relative%}
</div>
{% endif %}
